package com.ruoyi.web.East;

public class ByteUtils {

    /**
     * 16进制数字字符集
     */
    private static final String HEXSTRING = "0123456789ABCDEF";

    /**
     * 字节数据转为16进制字符串
     *
     * @param byteArray 接收到的客户端字节数据
     * @return 16进制字符串
     */
    public static String ByteArrayToHexStr(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }
        char[] hexArray = HEXSTRING.toCharArray();
        char[] hexChars = new char[byteArray.length * 2];
        for (int i = 0; i < byteArray.length; i++) {
            int temp = byteArray[i] & 0xFF;
            hexChars[i * 2] = hexArray[temp >>> 4];
            hexChars[i * 2 + 1] = hexArray[temp & 0x0F];
        }
        return new String(hexChars);
    }
}

